package com.zfast.yugioh.controller;

import com.github.pagehelper.PageInfo;
import com.zfast.forge.common.BaseResult;
import com.zfast.forge.common.Page;
import com.zfast.forge.valid.Create;
import com.zfast.yugioh.model.Card;
import com.zfast.yugioh.service.CardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 卡牌
 *
 * @author zgn
 * @email
 * @date 2022-06-08 16:56:12
 */
@RestController
@RequestMapping("api/card")
@Api(tags = {"卡牌Con"})
public class CardController{
    @Resource
    CardService cardService;

    @PostMapping({"/list"})
    @ApiOperation(value = "卡牌数据列表", httpMethod = "POST", notes = "获取卡牌列表")
    public BaseResult<PageInfo<Card>> list(@RequestBody Page<Card> page) {
        BaseResult result=BaseResult.builder()
                .msg("获取卡牌列表成功")
                .data(cardService.pageList(page.getData(),page.getNum(),page.getSize()))
                .build();
        return result;
    }

    @GetMapping({"/get/{id}"})
    @ApiOperation(value = "卡牌数据列表", httpMethod = "GET", notes = "获取单个卡牌记录")
    public BaseResult<Card> get(@ApiParam(name = "id", value = "业务对象主键", required = true) @PathVariable Integer id) {
        BaseResult result=BaseResult.builder()
                .msg("查询卡牌成功")
                .data(cardService.get(id))
                .build();
        return result;
    }

    @PostMapping({"add"})
    @ApiOperation(value = "新增卡牌信息", httpMethod = "POST", notes = "保存卡牌")
    public BaseResult<Integer> add(@RequestBody @Validated(Create.class) Card model) {
        BaseResult result=BaseResult.builder()
                .msg("添加卡牌成功")
                .data(cardService.insert(model))
                .build();
        return result;
    }

    @PostMapping({"update"})
    @ApiOperation(value = "更新指定id的 卡牌 信息（更新全部信息）", httpMethod = "POST", notes = "更新指定id的 卡牌 信息（更新全部信息）")
    public BaseResult<Integer> update(@RequestBody @ApiParam(name = "card", value = "卡牌业务对象", required = true) Card model) {
        BaseResult result=BaseResult.builder()
                .msg("更新卡牌成功")
                .data(cardService.update(model))
                .build();
        return result;
    }

    @GetMapping({"remove/{id}"})
    @ApiOperation(value = "删除卡牌记录", httpMethod = "GET", notes = "删除卡牌记录")
    public BaseResult<Integer> remove(@ApiParam(name = "id", value = "业务主键", required = true) @PathVariable Integer id) {
        BaseResult result=BaseResult.builder()
                .msg("删除卡牌成功")
                .data(cardService.delete(id))
                .build();
        return result;
    }
}
